const app = getApp()
Page({
    /**
     * 页面的初始数据
     */
    data: {},

    /**
     * 扫描发票
     */
    toScan: function () {
        wx.scanCode({
            success(res) {
                var result = res.result;
                if (result.split(",").length == 7 || result.split(",").length == 8 || result.split(",").length == 9) {
                    wx.navigateTo({
                      url: '../create/create?invoice=' + result,
                    })
                } else {
                    app.showErrorModal('异常', '暂不支持此类发票扫描添加，请手动输入', false);
                }
            },
            fail: _res => {
                app.showErrorModal('提示', '未扫描到有效的二维码', false);
            }
        })
    },

    /**
     * 手动录入
     */
    toWrite: function () {
        wx.navigateTo({
            url: '../create/create',
        })
    },

    /**
     * 查看全部发票
     */
    toView: function () {
        wx.navigateTo({
            url: '../list/list',
        })
    },
})